<template>
    <div class="vat">
        <div class="list clear" v-for="(item, index) in data">
            <div class="text fl">{{item.name}}</div>
            <div class="value fr">{{item.value}}</div>
        </div>
        <div class="margin"></div>
        <div class="btns" v-if="showBtns">
            <router-link class="btn see-city" :to="'/seecity?companyNumber=' + userInfo.companyNum">
                查看同城其他项目公司信息
            </router-link>
            <router-link class="btn see-all" :to="'/seeall'">查看集团全部</router-link>
        </div>
        <div @click="importToWX()" class="btn import-wx" >保存到"微信"-"我的发票抬头"</div>
    </div>
</template>

<script>
    import axios from 'axios';
    import { Toast } from 'mint-ui';
    import { mapState } from 'vuex';
    export default {
        data() {
            return {
                list: {},
                taxPayerType: {
                    '-1': '',
                    '1': '一般纳税人',
                    '2': '小规模纳税人'
                },
                maxAmtList: {
                    '0': '',
                    '11': '一千元',
                    '12': '一万元',
                    '13': '十万元',
                    '14': '一百万元',
                    '15': '一千万元',
                    '16': '一亿元'
                },
                showBtns: true
            };
        },
        computed: {
            data() {
                var obj = [
                    {
                        'name': '公司名称',
                        'value': this.list.companyName
                    },
                    {
                        'name': '开户行名称',
                        'value': this.list.bankName
                    },
                    {
                        'name': '开户行账号',
                        'value': this.list.bankAccount
                    },
                    {
                        'name': '纳税人识别号',
                        'value': this.list.taxRegistryNo
                    },
                    {
                        'name': '纳税人资质',
                        'value': this.taxPayerType[this.list.taxPayerType]
                    },
                    {
                        'name': '增值税专票最高限额',
                        'value': this.maxAmtList[this.list.maxAmt]
                    },
                    {
                        'name': '联系电话',
                        'value': this.list.tel
                    },
                    {
                        'name': '公司地址',
                        'value': this.list.address
                    }
                ];
                return obj;
            },
            ...mapState(['userInfo'])
        },
        created() {
            var companyNum = '';
            if (this.userInfo) {
                companyNum = this.userInfo.companyNum;
            }
            var companyNumber = this.$route.query.companyNumber || companyNum;
            if (this.$route.query.companyNumber) {
                this.showBtns = false;
            }
            let locData = localStorage.getItem('getLegalPersons');
            if (locData) {
                this.list = JSON.parse(locData);
            }
            var url = this.HOST + '?method=getLegalPersons&companyNumber=' + companyNumber + '&sessionID=' + this.SESSIONID;
            this.$http.post(url).then(res => {
                this.list = res.data;
                localStorage.setItem('getLegalPersons', JSON.stringify(this.list));
            });
        },
        methods: {
            importToWX () {
                let reqData = {
                    title: this.list.companyName || '',
                    phone: this.list.tel || '',
                    tax_no: this.list.taxRegistryNo || '',
                    addr: this.list.address || '',
                    bank_type: this.list.bankName || '',
                    bank_no: this.list.bankAccount || '',
                    user_fill: 0,
                    out_title_id: ''
                };
                axios({
                    method: 'get',
                    url: '/com/card_invoice_biz_getusertitleurl',
                    params: reqData,
                    headers: {
                        'X-Requested-With': 'XMLHttpRequest',
                        'Content-type': 'application/x-www-form-urlencoded;charset=utf-8'
                    }
                }).then(response => {
                    if (+response.data.status === 1) {
                        location.href = response.data.data.url;
                    } else {
                        Toast({message: '请求失败', duration: 2000});
                    }
                }).catch(error => {
                    Toast({message: error.message || '请求错误', duration: 2000});
                });
            }
        }
    };
</script>

<style lang="less" scoped>
    @import "../css/var.less";

    .vat {
        min-height: 100%;
        position: relative;
        .list {
            .value {
                 overflow: visible;
                 white-space: normal;
            }
        }
        .margin{
            height:.4rem;
        }
        .btns {
            /*position: absolute;*/
            width: 90%;
            bottom: 0;
            margin-left: 5%;
            .btn {
                position: static;
                display: block;
                width: 100%;
                margin-bottom: 0.14rem;
            }
        }
        .import-wx{
            position: relative;
            width: 90%;
            bottom: 0;
            margin-left: 5%;
        }
    }
</style>
